function setdate()
{
 // this.dateField=opener.dateField
  this.dateField=window.dialogArguments;
  this.inDate=dateField.value

  //Set today's in year,month,day
  var now=new Date()
  var day=now.getDate()
  var month=now.getMonth()
  var year=now.getFullYear()

  //if (year<100) {year+=1900}
  //else {year+=2000}            //For Y2K
  // ---if user input a date then anlizy it
  if (inDate.indexOf('-'))
  {
     var inYear=parseInt(inDate.substring(0,inDate.indexOf("-")))
              
     var inMonth=inDate.substring(inDate.indexOf("-")+1,inDate.lastIndexOf("-"))
         if ( inMonth.substring(0,1)=="0" && inMonth.length>1)
            {
              inMonth=inMonth.substring(1,inMonth.length)
            }
              inMonth=parseInt(inMonth)

     var inDay=inDate.substring(inDate.lastIndexOf("-")+1,inDate.length)
	         if (inDay.substring(0,1)=="0" && inDay.length>1)
             inDay=inDay.substring(1,inDay.length)
             inDay=parseInt(inDay)
     
     if (inDay){day=inDay}
     if (inMonth){month=inMonth-1}
     if (inYear){year=inYear}
  }
  this.focusDay=day
  var urlFlag = window.location.href.indexOf("?");
  //now.getHours()+":"+now.getMinutes();
  if(urlFlag > 0){
	  document.calControl.hour.style.display = "inline";
	  document.calControl.minute.style.display = "inline";
	  document.getElementById("timeSpliter").style.display = "inline";
	  document.calControl.hour.value = now.getHours();
	  document.calControl.minute.value = now.getMinutes();
  }
  document.calControl.month.selectedIndex=month
  document.calControl.year.value=year
  displayCalendar(day,month,year)
}

////////////////////////////////////////
function setToday()
{
    //set today's in year,month,day
  var now=new Date()
  var day=now.getDate()
  var month=now.getMonth()
  var year=now.getYear()
  //if (year<100) {year+=1900}
  //else {year+=2000}   //for Y2K
  this.focusDay=day
  document.calControl.month.selectedIndex=month
  document.calControl.year.value=year
  displayCalendar(day,month,year)
  /////////////////
  //////////////
  if (day==0) {var nowday=now.getDate()}
  else {var nowday=day}
  var days=getDaysInMonth(month+1,year)
  var firstOfMonth=new Date(year,month,1)
  var startingPos=firstOfMonth.getDay()
  document.CalButtons.elements[nowday+startingPos-1].focus()
}

////////////////////////////////////////
function isFourDigitYear(year)
{
   if(year.length!=4)
   {
      alert("Year's length Must be 4 .")
      document.calControl.year.select()
      document.calControl.year.focus()
   }
   else {return true}
}

////////////////////////////////////////
function selectDate()
{
    var year=document.calControl.year.value
    if (isFourDigitYear(year))
     {
        var day=0
        var month=document.calControl.month.selectedIndex
        displayCalendar(day,month,year) 
     }
}

////////////////////////////////////////
function setPreviousYear()
{
   var year=document.calControl.year.value
   if (isFourDigitYear(year))
   {
       var day=0
       var month=document.calControl.month.selectedIndex 
       year--
       document.calControl.year.value=year
       displayCalendar(day,month,year)
   }
}

////////////////////////////////////////
function setPreviousMonth()
{
   var year=document.calControl.year.value
   if (isFourDigitYear(year))
   {
       var day=0
       var month=document.calControl.month.selectedIndex 
       if (month==0)
       {
          month=11
          if (year>1000)
             {
                year--
                document.calControl.year.value=year
             }
       }
       else{month--}
       document.calControl.month.selectedIndex=month
       displayCalendar(day,month,year)
   }
}

////////////////////////////////////////
function setnextMonth()
{
   var year=document.calControl.year.value
   if(isFourDigitYear(year))
   {
      var day=0
      var month=document.calControl.month.selectedIndex
      if(month==11)
         {
            month=0
            year++
            document.calControl.year.value=year
         }
         else{month++}
         document.calControl.month.selectedIndex=month
         displayCalendar(day,month,year)
   }
}
////////////////////////////////////////
function setnextYear()
{
   var year=document.calControl.year.value
   if(isFourDigitYear(year))
   {
      var day=0
      var month=document.calControl.month.selectedIndex
      year++
      document.calControl.year.value=year
      displayCalendar(day,month,year)
   }
}
////////////////////////////////////////
function displayCalendar(day,month,year)
{
  day=parseInt(day)
  month=parseInt(month)
  year=parseInt(year)
  var i=0
  var now=new Date()
  
  if (day==0) {var nowday=now.getDate()}
  else {var nowday=day}
  var days=getDaysInMonth(month+1,year)
  var firstOfMonth=new Date(year,month,1)
  var startingPos=firstOfMonth.getDay()
  days+=startingPos
  
  //空开一个月的第一个星期里不属于这个月的几天
  for (i=0;i<startingPos;i++)
  {
    document.CalButtons.elements[i].value=""
    document.CalButtons.elements[i].style.visibility="hidden"
    //window.CalButtons.but0.style.visibility="hidden"    
  }
  //写上一个月中的每一天
  for (i=startingPos;i<days;i++)
  {
     document.CalButtons.elements[i].value=i-startingPos+1
     document.CalButtons.elements[i].style.visibility="visible"
  }
  //一个月最后一个星期中不属于这个月的几天也应该为空
  for (i=days;i<37;i++)
  {
     document.CalButtons.elements[i].value=""
     document.CalButtons.elements[i].style.visibility="hidden"
  }
  //在当前的日子设置焦点
//  document.CalButtons.elements[nowday+startingPos-1].focus()
}

////////////////////////////////////////////
//获得一个月中的天数
////////////////////////////////////////////
function getDaysInMonth(month,year)
{
   var days
   if (month==1||month==3||month==5||month==7||month==8||month==10||month==12) days=31
      else if (month==4||month==6||month==9||month==11) days=30
            else if (month==2) 
                  {
                    if (isLeapYear(year)){days=29}
                    else {days=28}
                  }
  return (days)
}

//////////////////////////////////////////////
// Check for Leap Year
/////////////////////////////////////////////
function isLeapYear(year)
{
   if (((year%4)==0)&&((year%100)!=0)||((year%400)==0))
       {
         return (true)
       }
       else {return (false)}
}

//////////////////////////////////////////////
//从日历中获得数据
//////////////////////////////////////////////
function returnDate(inDay)
{
  var day=inDay;
  var month=(document.calControl.month.selectedIndex)+1;
  var year=document.calControl.year.value;
  var nowDate = new Date();
  if ((""+month).length==1) {month="0"+month;}
  if ((""+day).length==1){day="0"+day;}
  if (day!=" ")
  { 
    var currTime = " "+document.calControl.hour.value+":"+document.calControl.minute.value;
    var urlFlag = window.location.href.indexOf("?");
	dateField.value= inDay == "" ? "":year+"-"+month+"-"+day+(urlFlag > 0 ? currTime:"");
    window.close ();
  }
}

function document_onmousedown() {
if (window.event.button!=1)
    {
       alert("/////////////////////////////////////////\n// Author  : Bo Lee                      //\n// Freezing_land@hotmail.com   //\n// Copyright By: UnifiedCommunications.com       //\n// Date    : 3-21-2001 12:40 PM //\n/////////////////////////////////////////")
    }
}

